﻿<%@ Page Language="C#" MasterPageFile="~/InventoryTracker/MasterPage.master" AutoEventWireup="true" CodeFile="Dr.aspx.cs" Inherits="InventoryTracker_Dr" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="maincontent" Runat="Server">
<body>
    <form id="form1" >    
    <h3>Editing individual Grid<asp:GridView ID="GridView1" runat="server" 
            AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" 
            GridLines="None" DataSourceID="SDBS" DataKeyNames="Id"
            OnRowDataBound="GridView1_RowDataBound" 
            OnRowCommand="GridView1_RowCommand" OnRowUpdating="GridView1_RowUpdating" 
            AllowSorting="True" AllowPaging="True" PageSize="4" 
           >
            <Columns>                
                <asp:ButtonField Text="SingleClick" CommandName="SingleClick" Visible="False"/>
                <asp:TemplateField HeaderText="Id" SortExpression="Id">
                    <ItemTemplate>
                        <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>'></asp:Label>
                        <asp:TextBox ID="Id" runat="server" Text='<%# Eval("Id") %>' Width="30px" visible="false"></asp:TextBox>
                    </ItemTemplate>               
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Item Name" SortExpression="AssignedTo">
                    <ItemTemplate>
                        <asp:Label ID="ItemNameLabel" runat="server" Text=''></asp:Label>
                        <asp:DropDownList ID="ItemName" runat="server" Visible="True" AutoPostBack="true" CausesValidation="true">
                            <asp:ListItem></asp:ListItem>
                            <asp:ListItem>Andy</asp:ListItem>
                            <asp:ListItem>Betty</asp:ListItem>
                            <asp:ListItem>Conor</asp:ListItem>
                            <asp:ListItem>Declan</asp:ListItem>
                            <asp:ListItem>Eamon</asp:ListItem>
                            <asp:ListItem>Fergal</asp:ListItem>
                            <asp:ListItem>Gordon</asp:ListItem>
                            <asp:ListItem>Helen</asp:ListItem>
                            <asp:ListItem>Iris</asp:ListItem>
                            <asp:ListItem>John</asp:ListItem>
                            <asp:ListItem>Kevin</asp:ListItem>
                            <asp:ListItem>Lorna</asp:ListItem>
                            <asp:ListItem>Matt</asp:ListItem>
                            <asp:ListItem>Nora</asp:ListItem>
                            <asp:ListItem>Olive</asp:ListItem>
                            <asp:ListItem>Peter</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="ItemDescription" SortExpression="Status">
                    <ItemTemplate>
                        <asp:Label ID="DescriptionLabel" runat="server" Text=''></asp:Label>
                        <asp:DropDownList ID="DescriptionD" runat="server" Visible="True" AutoPostBack="true" CausesValidation="true">
                            <asp:ListItem>Pending</asp:ListItem>
                            <asp:ListItem>In Progress</asp:ListItem>
                            <asp:ListItem>Complete</asp:ListItem>
                            <asp:ListItem>Cancelled</asp:ListItem>
                            <asp:ListItem>Suspended</asp:ListItem>
                        </asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Tax" SortExpression="Description">
                    <ItemTemplate>
                        <asp:Label ID="Tax" runat="server" Text=''></asp:Label>
                        <asp:TextBox ID="TaxTextBox" runat="server"  Width="175px" visible="false"></asp:TextBox>
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle CssClass="headerStyle" ForeColor="White" BackColor="#5D7B9D" 
                Font-Bold="True" />
            <RowStyle CssClass="rowStyle" BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <AlternatingRowStyle CssClass="alternatingRowStyle" BackColor="White" 
                ForeColor="#284775" />
            <FooterStyle CssClass="footerStyle" BackColor="#5D7B9D" Font-Bold="True" 
                ForeColor="White" />
            <PagerStyle CssClass="pagerStyle" ForeColor="White" BackColor="#284775" 
                HorizontalAlign="Center" />
        </asp:GridView>
        <asp:SqlDataSource ID="SDBS" runat="server" 
            ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
            DeleteCommand="DELETE FROM NewTab WHERE (Id = @Id)" 
            InsertCommand="INSERT INTO NewTab(ItemName, ItemDescription, Tax) VALUES (@ItemName, @ItemDescription, @Tax)" 
            SelectCommand="SELECT NewTab.* FROM NewTab" 
            UpdateCommand="UPDATE NewTab SET ItemName = @ItemName, ItemDescription = @ItemDescription, Tax = @Tax WHERE (Id = @Id)">
            <DeleteParameters>
                <asp:Parameter Name="Id" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="ItemName" />
                <asp:Parameter Name="ItemDescription" />
                <asp:Parameter Name="Tax" />
                <asp:Parameter Name="Id" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="ItemName" />
                <asp:Parameter Name="ItemDescription" />
                <asp:Parameter Name="Tax" />
            </InsertParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="SDB" runat="server"></asp:SqlDataSource>
        View cells using a SQL Data Source control</h3>
    <a href="Default.aspx">Back to Menu</a>
    <p>
        This example uses sample data which is stored in a SQL Server database.
        <br />The data is accessed via a SQL Data Source control.
        <br />Paging and Sorting functionality has also been added.
        <br />Try clicking and editing the individual GridView cells.
    </p>    
    <div>        
        <br /><br />
        <asp:Label id="Message" runat="server" CssClass="message"></asp:Label> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
            DeleteCommand="DELETE FROM [Tasks] WHERE [Id] = @Id" InsertCommand="INSERT INTO [Tasks] ([Description], [AssignedTo], [Status]) VALUES (@Description, @AssignedTo, @Status)"
            SelectCommand="SELECT * FROM [Tasks]" UpdateCommand="UPDATE [Tasks] SET [Description] = @Description, [AssignedTo] = @AssignedTo, [Status] = @Status WHERE [Id] = @Id" >
            <DeleteParameters>
                <asp:Parameter Name="Id" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="AssignedTo" Type="String" />
                <asp:Parameter Name="Status" Type="String" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Description" Type="String" />
                <asp:Parameter Name="AssignedTo" Type="String" />
                <asp:Parameter Name="Status" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>  
     </div>
    </form>
</body>


</asp:Content>

